package com.ruoyi.system.controller;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.security.annotation.PreAuthorize;
import com.ruoyi.system.domain.SysLoginInfo;
import com.ruoyi.system.service.ISysLoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 系统访问记录
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/logininfor")
public class SysLoginInfoController extends com.ruoyi.common.core.web.controller.BaseController
{
    @Autowired
    private ISysLoginInfoService loginInfoService;

    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:logininfor:list")
    @GetMapping("/list")
    public com.ruoyi.common.core.web.page.TableDataInfo list(SysLoginInfo logininfor)
    {
        startPage();
        List<SysLoginInfo> list = loginInfoService.selectLogininforList(logininfor);
        return getDataTable(list);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:logininfor:export")
    @PostMapping(value="/export", produces = "application/octet-stream")
    public void export(HttpServletResponse response, SysLoginInfo logininfor) throws IOException
    {
        List<SysLoginInfo> list = loginInfoService.selectLogininforList(logininfor);
        com.ruoyi.common.core.utils.poi.ExcelUtil<SysLoginInfo> util = new com.ruoyi.common.core.utils.poi.ExcelUtil<SysLoginInfo>(SysLoginInfo.class);
        util.exportExcel(response, list, "登录日志");
    }

    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:logininfor:remove")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public com.ruoyi.common.core.web.domain.AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(loginInfoService.deleteLogininforByIds(infoIds));
    }

    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:logininfor:remove")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/clean")
    public com.ruoyi.common.core.web.domain.AjaxResult clean()
    {
        loginInfoService.cleanLogininfor();
        return com.ruoyi.common.core.web.domain.AjaxResult.success();
    }


    @PostMapping
    public com.ruoyi.common.core.web.domain.AjaxResult add(@RequestBody SysLoginInfo logininfor)
    {
        return toAjax(loginInfoService.insertLogininfor(logininfor));
    }
}
